#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# @Project:     py_utils
# @File:        u_schedule.py
# @Author:      Fan GuiChuan
# @Date:        2024/8/19 11:38
# @Version:     Python3.7
# @Description:
import logging
from multiprocessing import Process

from .u_loader import PluginLoader


class PluginScheduler(Process):
    """
    插件调度器
    """
    def __init__(self,
                 plugin_dir: str,
                 logger: logging.Logger,
                 plugin_file_suffix: str = '',
                 config: dict = None):
        """
        插件调度器
        """
        self.__plugin_loader = PluginLoader(plugin_dir, logger)

    def __start_plugins(self, plugin_info):
        """
        启动插件
        """
        p = plugin_info['cls']
        p()

    def run(self):
        print(f"start plugin schedule...")
        plugins_info = self.__plugin_loader.load_plugins()
        print(f"plugin info: {plugins_info}")
        for plugin_name in plugins_info:
            self.__start_plugins(plugins_info[plugin_name])
